package com.example.sandbox.helper;

import lombok.Getter;

import java.util.Objects;

/**
 * <p>
 * 业务异常（无关于请求状态）
 * </p>
 *
 * @author liuxinxin
 * @since 2024/04/22
 */
@Getter
public class BizException extends RuntimeException {

    private static final long serialVersionUID = 5755682573152415431L;

    private Integer code;

    public BizException(String message) {
        super(message);
    }

    public BizException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    public BizException(BizMessage bizMessage) {
        super(bizMessage.getMessage());
        this.code = bizMessage.getCode();
    }

    public String getStrCode() {
        if (Objects.isNull(code)) {
            return "";
        }
        return this.code.toString();
    }
}
